package org.summer.generator;

import java.sql.Types;

/**
 * 数据类型转换器，将sql数据类型转换为需要的数据类型
 */
public class DataTypeConverter {

    /**
     * 将sql数据类型转换为java数据类型
     * @param sqlType
     * @return
     */
    public static String convertToJavaType(int sqlType){
        return switch (sqlType){
            case Types.BIGINT -> "Long";
            case Types.INTEGER,Types.TINYINT -> "Integer";
            case Types.VARCHAR,Types.CHAR,Types.JAVA_OBJECT -> "String";
            case Types.DATE -> "LocalDate";
            case Types.TIME -> "LocalTime";
            case Types.TIMESTAMP -> "LocalDateTime";
            case Types.DECIMAL -> "BigDecimal";
            case Types.DOUBLE -> "Double";
            case Types.BOOLEAN,Types.BIT -> "Boolean";
            default -> "Object";
        };
    }

    /**
     * sql数据类型转换为ts类型
     */
    public static String convertToTypescript(int sqlType){
        return switch (sqlType){
            case Types.INTEGER,Types.TINYINT,Types.BIGINT,Types.DECIMAL -> "number";
            case Types.VARCHAR,Types.CHAR -> "string" ;
            case Types.BOOLEAN,Types.BIT -> "boolean";
            case Types.DATE,Types.TIMESTAMP,Types.TIME -> "Date";
            default -> "object";
        } ;
    }


}
